import requests
import re


def seebug(cms):
    r = requests.get(
        "https://www.seebug.org/search/?keywords=dedecms"
    )

    m = re.search(r'(__jsluid_s=.*?);', r.headers.get("Set-Cookie"))
    jsluid = m.group(1)

    r = requests.get(
        "https://www.seebug.org/search/?keywords={}&category=&level=high".format(cms),
        headers={
            "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko)"
                            " Chrome/91.0.4472.114 Safari/537.36",
            # "Cookie": "{}; {};".format(jsluid, clearance)
            "Cookie": jsluid
        },
    )

    # print(r.text)
    data = re.findall(r'class="vul-title" title="(.*?)" href="(.*?)"', r.text)
    results = []

    for item in data:
        print(item)
        title, target = item
        target = "https://www.seebug.org" + target

        results.append(
            {"type": "Plain", "text": "{} {}\n".format(title, target)}
        )
    return results

# print(r.text)
